Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
dom-storage
Advanced tools
The dom-storage npm package is a simple implementation of the W3C DOM Storage API, which provides a way to store key-value pairs in a web browser. It is useful for server-side JavaScript environments like Node.js where the browser's localStorage and sessionStorage are not available.
localStorage
This feature allows you to use localStorage in a Node.js environment. You can set, get, remove, and clear items just like you would in a browser.
const { LocalStorage } = require('dom-storage');
const localStorage = new LocalStorage('./localStorage');
// Set an item
localStorage.setItem('key', 'value');
// Get an item
const value = localStorage.getItem('key');
console.log(value); // Outputs: 'value'
// Remove an item
localStorage.removeItem('key');
// Clear all items
localStorage.clear();
sessionStorage
This feature allows you to use sessionStorage in a Node.js environment. You can set, get, remove, and clear items just like you would in a browser.
const { SessionStorage } = require('dom-storage');
const sessionStorage = new SessionStorage();
// Set an item
sessionStorage.setItem('key', 'value');
// Get an item
const value = sessionStorage.getItem('key');
console.log(value); // Outputs: 'value'
// Remove an item
sessionStorage.removeItem('key');
// Clear all items
sessionStorage.clear();
node-localstorage is another package that provides a localStorage API for Node.js. It is similar to dom-storage but focuses solely on localStorage functionality. It also supports persistence by writing data to disk.
localstorage-memory is an in-memory implementation of the localStorage API for Node.js. Unlike dom-storage, it does not persist data to disk, making it suitable for testing and temporary storage.
node-persist is a more general-purpose storage library for Node.js that supports both key-value storage and JSON object storage. It offers more flexibility compared to dom-storage but may be overkill if you only need localStorage or sessionStorage functionality.
| dom-storage | atob | btoa | unibabel.js | Sponsored by ppl
An inefficient, but as W3C-compliant as possible using only pure JavaScript, DOMStorage
implementation.
This is meant for the purpose of being able to run unit-tests and such for browser-y modules in node.
var Storage = require('dom-storage');
// in-file, doesn't call `String(val)` on values (default)
var localStorage = new Storage('./db.json', { strict: false, ws: ' ' });
// in-memory, does call `String(val)` on values (i.e. `{}` becomes `'[object Object]'`
var sessionStorage = new Storage(null, { strict: true });
var myValue = { foo: 'bar', baz: 'quux' };
localStorage.setItem('myKey', myValue);
myValue = localStorage.getItem('myKey');
// use JSON to stringify / parse when using strict w3c compliance
sessionStorage.setItem('myKey', JSON.stringify(myValue));
myValue = JSON.parse(localStorage.getItem('myKey'));
[Object object]
or as json { foo: bar }
.' '
.0 === localStorage.length;
null === localStorage.getItem('doesn\'t exist');
undefined === localStorage['doesn\'t exist'];
localStorage.setItem('myItem');
'undefined' === localStorage.getItem('myItem');
1 === localStorage.length;
localStorage.setItem('myItem', 0);
'0' === localStorage.getItem('myItem');
localStorage.removeItem('myItem', 0);
0 === localStorage.length;
localStorage.clear();
0 === localStorage.length;
Storage
events (not sure how to do)Code copyright 2012-2018 AJ ONeal
Dual-licensed MIT and Apache-2.0
Docs copyright 2012-2018 AJ ONeal
Docs released under Creative Commons.
FAQs
W3C DOM Storage (localStorage and sessionStorage) for node.js
We found that dom-storage demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.